// 在Class出来之前我们使用原型链来定义对象
function Person(name) {
    this.name = name
}

Person.prototype.say = function() {
    console.log(this.name)
}

const p = new Person("sanfeng_hu")
p.say()

// 使用class 
class PersonClass {
    constructor(name) {
        this.name = name
    }

    say() {
        console.log(this.name)
    }
}

let p1 = new PersonClass("sanfeng_hu_class")
p1.say()

// 在上述say 方法是实例方法，在class中有个静态方法，直接使用类来调用，只需要在
// 定义方法时，添加static 关键字
class PersonClassStatc {
    constructor(name) {
        this.name = name
    }

    static create(name) {
        return new PersonClassStatc(name)
    }

    say() {
        console.log(this.name)
    }
}

let p2 = PersonClassStatc.create("sanfeng_hu_class_static")
p2.say()

// 类的继承 extends
class Student extends PersonClass {
    constructor(name,age) {
        // 调用父类的构造函数
        super(name)
        this.age = age
    }
    sayInfo() {
        console.log(`${this.name}${this.age}`)
    }
}

let student = new Student("sanfeng_hu", 18)
student.sayInfo()